package com.xyht.sca_s.student_manage_system.modules.assetConsumableBorrow.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.assetConsumableBorrow.entity.req.SmsAssetConsumableBorrowApplyAllowReq;
import com.xyht.sca_s.student_manage_system.modules.assetConsumableBorrow.entity.req.SmsAssetConsumableBorrowApplyReq;
import com.xyht.sca_s.student_manage_system.modules.assetConsumableBorrow.service.SmsAssetConsumableBorrowApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-06-30
 */
@RestController
@RequestMapping("/assetConsumable/BorrowApply")
@SecretBody
public class SmsAssetConsumableBorrowApplyController {
    @Autowired
    SmsAssetConsumableBorrowApplyService smsAssetConsumableBorrowApplyService;
    @Autowired
    JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "新增固定资产借用申请")
    @PostMapping("/add")
    public ResponseResult smsAssetConsumableBorrowApplyAdd(@RequestBody SmsAssetConsumableBorrowApplyReq applyReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableBorrowApplyService.smsAssetConsumableBorrowApplyAdd(applyReq, userId);
    }

    @ApiModelProperty(value = "撤销借用申请")
    @PostMapping("/cancel")
    public ResponseResult smsAssetConsumableBorrowApplyCancel(@RequestBody SmsAssetConsumableBorrowApplyReq cancelReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableBorrowApplyService.smsAssetConsumableBorrowApplyCancel(cancelReq, userId);
    }

    @ApiModelProperty(value = "审批")
    @PostMapping("/allow")
    public ResponseResult smsAssetConsumableBorrowApplyAllow(@RequestBody SmsAssetConsumableBorrowApplyAllowReq allowReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableBorrowApplyService.smsAssetConsumableBorrowApplyAllow(allowReq, userId);
    }

    @ApiModelProperty(value = "审批列表")
    @GetMapping("/list")
    public ResponseResult getAssetConsumableBorrowApplyList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(value = "applyType") Integer applyType,
                                                            HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableBorrowApplyService.getAssetConsumableBorrowApplyList(pageSize, pageNum, applyType, userId);
    }

    @ApiModelProperty(value = "审批详情")
    @GetMapping("/detail")
    public ResponseResult getAssetConsumableBorrowApplyDetail(@RequestParam(value = "applyId") String applyId, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableBorrowApplyService.getAssetConsumableBorrowApplyDetail(applyId, userId);
    }

    @ApiModelProperty(value = "查询所有申请记录")
    @GetMapping("/selectAll")
    public ResponseResult selectAllAssetConsumableBorrowApply(@RequestParam(value = "applyPerson", required = false) String applyPerson,
                                                              @RequestParam(value = "applyDepartment", required = false) String applyDepartment,
                                                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return smsAssetConsumableBorrowApplyService.selectAllAssetConsumableBorrowApply(applyPerson, applyDepartment, pageSize, pageNum);
    }

    @ApiModelProperty(value = "根据id查申请记录查询")
    @GetMapping("/selectDetail")
    public ResponseResult selectDetail(@RequestParam(value = "id", required = false) String id) {
        return smsAssetConsumableBorrowApplyService.selectDetail(id);
    }
}